<script type="text/javascript">
$(function () {
	$.ajaxSetup({cache: false});
	bindEvent();
});

function saveConfig() {
	sys_loading();
	var parm = $('#editOrganConfigForm').serialize();
	var url = create_url('organConfig-save');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			if (result == 'success')
				//sys_msg('操作成功!');
				alert('保证成功!');
			else
				sys_msg('保存失败!');
		}
	});
}

function bindEvent() {
	$("#selectCmoc").click(function(e) { // 选择中国移动录单机构
		var oc = $(this).siblings("input:eq(0)").attr("id");
		var on = $(this).siblings("input:eq(1)").attr("id");
		selectOrgan(oc, on);
	});
	$("#clearCmoc").click(function(e) { // 清除中国移动录单机构
		$(this).siblings("input").val("");
	});
	$("#selectCuoc").click(function(e) { // 选择中国联通录单机构
		var oc = $(this).siblings("input:eq(0)").attr("id");
		var on = $(this).siblings("input:eq(1)").attr("id");
		selectOrgan(oc, on);
	});
	$("#clearCuoc").click(function(e) { // 清除中国联通录单机构
		$(this).siblings("input").val("");
	});
	$("#selectCtoc").click(function(e) { // 选择中国电信录单机构
		var oc = $(this).siblings("input:eq(0)").attr("id");
		var on = $(this).siblings("input:eq(1)").attr("id");
		selectOrgan(oc, on); 
	});
	$("#clearCtoc").click(function(e) { // 清除中国电信录单机构
		$(this).siblings("input").val("");
	});
	
	/* 判断如果[采购订单是否需要财务确认]的radio的值,如果选中[否],不显示后面的角色select */
	var pCfoRadioChecked = $("input[name='orderCfoConfirm']:checked");
	var porc = $("select#porc");
	if (pCfoRadioChecked.val() == "false") porc.hide();
	/* 判断如果[渠道订单是否需要财务确认]的radio的值,如果选中[否],不显示后面的角色select */
	var dCfoRadioChecked = $("input[name='orderDdmCfoConfirm']:checked");
	var dorc = $("select#dorc");
	if (dCfoRadioChecked.val() == "false") dorc.hide();
	/* 判断如果[采购订单是否需要经理确认]的radio的值,如果选中[否],不显示后面的角色select */
	var pCeoRadioChecked = $("input[name='orderCeoConfirm']:checked")
	var ceo = $("select#ceo");
	if (pCeoRadioChecked.val() == "false") ceo.hide();
	
	/* 如果[采购订单是否需要财务确认]的radio选择[是],显示后面的select,反之隐藏 */
	$("input[name='orderCfoConfirm']").click(function(e) {
		if (this.value == "true") porc.show();
		else if (this.value == "false") porc.hide();
	});
	
	/* 如果[渠道订单是否需要财务确认]的radio选择[是],显示后面的select,反之隐藏 */
	$("input[name='orderDdmCfoConfirm']").click(function(e) {
		if (this.value == "true") dorc.show();
		else if (this.value == "false") dorc.hide();
	});
	
	/* 如果[采购订单是否需要总经理确认]的radio选择[是],显示后面的select,反之隐藏 */
	$("input[name='orderCeoConfirm']").click(function(e) {
		if (this.value == "true") ceo.show();
		else if (this.value == "false") ceo.hide();
	});
	
	
	
}

function selectOrgan(oc, on) {
	var url = create_url("organConfig-aidInit");
	var parm = {oc: oc, on: on};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}
</script>

<#import "/freemarker/modeltype.ftl" as mt>
<#import "/freemarker/modeltype_entity.ftl" as mte>

<div class="widget" style="width:1000px;float:left;">
	<div class="widget-header">
		<h3 class="title"><i class="fontello-icon-th-list-1"></i> 机构配置</h3>
	</div>
	<div class="widget-content">
		<div>当前机构: ${currentOrgan.name}</div>
		<form id="editOrganConfigForm">
			<input type="hidden" name="code" value="${currentOrgan.code}" />
			<table class="table boo-table table-content">
				<tr>
					<td class="table-left">采购订单是否需要财务确认</td>
					<td style="width:213px;"><@mt.YesOrNo value=((currentOrgan.orderCfoConfirm)!'false') r=true name='orderCfoConfirm' d=false mc=false /></td>
					<td class="table-left" style="width:99px;">确认角色</td>
					<td>
						<select name="porc" id="porc">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.porc == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">经销商订单是否需要财务确认</td>
					<td><@mt.YesOrNo value=((currentOrgan.orderDdmCfoConfirm)!'false') r=true name='orderDdmCfoConfirm' d=false mc=false /></td>
					<td class="table-left">确认角色</td>
					<td>
						<select name="dorc" id="dorc">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.dorc == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">订单是否需要总经理确认</td>
					<td><@mt.YesOrNo value=((currentOrgan.orderCeoConfirm)!'false') r=true name='orderCeoConfirm' d=false mc=false /></td>
					<td class="table-left">确认角色</td>
					<td>
						<select name="ceo" id="ceo">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.ceo == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">出纳角色</td>
					<td colspan="3">
						<select name="cashier" id="cashier">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.cashier == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">库房管理员角色</td>
					<td colspan="3">
						<select name="storer" id="storer">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.storer == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">售后角色</td>
					<td colspan="3">
						<select name="assp" id="assp">
							<option value="0">无角色</option>
							<#list rootRoles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.assp == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left" style="width:250px;">库存可见度</td>
					<td colspan="3">
						<select name="stockVisibility" id="stockVisibility">
							<option <#if currentOrgan.stockVisibility == '1'>selected="selected"</#if> value="1">不可见</option>
							<option <#if currentOrgan.stockVisibility == '2'>selected="selected"</#if> value="2">本机构库存</option>
							<option <#if currentOrgan.stockVisibility == '3'>selected="selected"</#if> value="3">本机构及一级子机构库存</option>
							<option <#if currentOrgan.stockVisibility == '4'>selected="selected"</#if> value="4">本机构及所有子机构库存</option>
							<option <#if currentOrgan.stockVisibility == '5'>selected="selected"</#if> value="5">本机构及分销机构库存</option>
							<option <#if currentOrgan.stockVisibility == '6'>selected="selected"</#if> value="6">本机构,分销机构及所有一级子机构库存</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">列表每页显示条数</td>
					<td colspan="3"><input type="text" name="pageSize" value="${currentOrgan.pageSize}" style="width:50px;" /></td>
				</tr>
				<tr>
					<td class="table-left">商品信息列表中是否显示进货价</td>
					<td colspan="3"><@mt.YesOrNo value=((currentOrgan.showPp)!false) r=true name='showPp' d=false mc=true /></td>
				</tr>
				<tr>
					<td class="table-left">商品信息列表中是否显示渠道价</td>
					<td colspan="3"><@mt.YesOrNo value=((currentOrgan.showDp)!false) r=true name='showDp' d=false mc=true /></td>
				</tr>
				<tr>
					<td class="table-left">商品信息列表中是否显示零售价</td>
					<td colspan="3"><@mt.YesOrNo value=((currentOrgan.showRp)!false) r=true name='showRp' d=false mc=true /></td>
				</tr>
				<tr>
					<td class="table-left">商品信息列表中是否显示品牌</td>
					<td colspan="3"><@mt.YesOrNo value=((currentOrgan.showBrand)!false) r=true name='showBrand' d=false mc=true /></td>
				</tr>
				<tr>
					<td class="table-left">摆柜机比例</td>
					<td colspan="3"><input type="text" name="cdr" value="${(currentOrgan.cdr)!''}" style="width:50px;" /></td>
				</tr>
				<tr>
					<td class="table-left">商品最短预计销售时间</td>
					<td colspan="3"><input type="text" name="spd" value="${(currentOrgan.spd)!''}" /></td>
				</tr>
				<tr>
					<td class="table-left">财务设置账期时间</td>
					<td colspan="3"><input type="text" name="ft" value="${(currentOrgan.ft)!''}" /></td>
				</tr>
				<tr>
					<td class="table-left">渠道账期时间</td>
					<td colspan="3"><input type="text" name="cht" value="${(currentOrgan.cht)!''}" /></td>
				</tr>
				<tr>
					<td class="table-left">销售主管账期时间</td>
					<td colspan="3"><input type="text" name="st" value="${(currentOrgan.st)!''}" /></td>
				</tr>
				<tr>
					<td class="table-left">中国移动录单机构</td>
					<td colspan="3">
						<div class="input-append btn-bar">
							<input name="cmocn" id="cmocn" value="${(currentOrgan.cmocn)}" class="span4" size="16" type="text" style="width:200px;" readonly="readonly" />
							<input type="hidden" name="cmoc" id="cmoc" value="${(currentOrgan.cmoc)}" />
							<button class="btn btn-glyph" type="button" title="选择该用户所属机构" id="selectCmoc"><i class="fontello-icon-pencil-4"></i></button>
							<button class="btn btn-glyph" type="button" title="去除机构查询条件" id="clearCmoc"><i class="fontello-icon-cancel-1"></i></button>
						</div>
					</td>
				</tr>
				<tr>
					<td class="table-left">中国联通录单机构</td>
					<td colspan="3">
						<div class="input-append btn-bar">
							<input name="cuocn" id="cuocn" value="${(currentOrgan.cuocn)}" class="span4" size="16" type="text" style="width:200px;" readonly="readonly" />
							<input type="hidden" name="cuoc" id="cuoc" value="${(currentOrgan.cuoc)}" />
							<button class="btn btn-glyph" type="button" title="选择该用户所属机构" id="selectCuoc"><i class="fontello-icon-pencil-4"></i></button>
							<button class="btn btn-glyph" type="button" title="去除机构查询条件" id="clearCuoc"><i class="fontello-icon-cancel-1"></i></button>
						</div>
					</td>
				</tr>
				<tr>
					<td class="table-left">中国电信录单机构</td>
					<td colspan="3">
						<div class="input-append btn-bar">
							<input name="ctocn" id="ctocn" value="${(currentOrgan.ctocn)}" class="span4" size="16" type="text" style="width:200px;" readonly="readonly" />
							<input type="hidden" name="ctoc" id="ctoc" value="${(currentOrgan.ctoc)}" />
							<button class="btn btn-glyph" type="button" title="选择该用户所属机构" id="selectCtoc"><i class="fontello-icon-pencil-4"></i></button>
							<button class="btn btn-glyph" type="button" title="去除机构查询条件" id="selectCtoc"><i class="fontello-icon-cancel-1"></i></button>
						</div>
					</td>
				</tr>
				<tr>
					<td class="table-left">手机系数</td>
					<td><input type="text" id="mobCoe" name="mobCoe" value="${(currentOrgan.mobCoe)}" style="width:50px;" /></td>
					<td class="table-left"">配件系数</td>
					<td><input type="text" id="fitCoe" name="fitCoe" value="${(currentOrgan.fitCoe)}" style="width:50px;" /></td>
				</tr>
				<tr>
					<td class="table-left">酬金系数</td>
					<td><input type="text" id="remCoe" name="remCoe" value="${(currentOrgan.remCoe)}" style="width:50px;" /></td>
					<td class="table-left"">其他系数</td>
					<td><input type="text" id="othCoe" name="othCoe" value="${(currentOrgan.othCoe)}" style="width:50px;" /></td>
				</tr>
				<tr>
					<td class="table-left">销售员角色编号</td>
					<td colspan="3">
						<select name="sarc" id="sarc">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.sarc == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">店长角色编号</td>
					<td colspan="3">
						<select name="ssrc" id="ssrc">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.ssrc == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td class="table-left">渠道管理员角色编号</td>
					<td colspan="3">
						<select name="cmrc" id="cmrc">
							<option value="0">无角色</option>
							<#list roles as role>
							<option value="${(role.code)!''}" <#if (currentOrgan.cmrc == role.code)>selected="selected"</#if>>${(role.name)!''}</option>
							</#list>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="4" style="text-align: center;">
						<a href="#" class="btn btn-info" onclick="javascript: saveConfig(); return false;">
							<i class="fontello-icon-floppy"></i>&nbsp;保&nbsp;&nbsp;存
						</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>